﻿/* Show dialog for passed dialog (or id of window)
 * Parameters:
 * dialog - Either an instance of dialog window or ID
 *		of component representing dialog window
 * args - Arguments taht should be passed to window eg.
 *		{foo: 'bar', id: 1}
 */
function showDialog(dialog, args){
	if(typeof(dialog) == 'String'){
		dialog = Ext.getCmp(dialog);
	}
	debugger;
	if(!dialog){
		alert('Could not find dialog to show');
		return;
	}
	var url = dialog.url;
	
	if(args){
		if(typeof(args) == 'String'){
			url = Ext.urlAppend(url, args);
		} else {
			url = Ext.urlAppend(url, Ext.urlEncode(args));
		}
	}
	
	dialog.loadIFrame({
		url: url,
		showMask: true,
		text: 'Loading...',
		scripts: true
	});
	
	dialog.show();
}

/*
 * Open tab in parent tab panel.
 * Parameters:
 *  url - url of aspx page to open
 *  args -  Arguments taht should be passed to tab eg.
 *		{foo: 'bar', id: 1}
 */
function openTab(url, args){
	var elements = parent.Ext.select('div{tabParent="true"}').elements;
	
	if(!elements.length ){
		return;
	}
	
	if(args){
		if(typeof(args) == 'String'){
			url = Ext.urlAppend(url, args);
		} else {
			url = Ext.urlAppend(url, Ext.urlEncode(args));
		}
	}
	
	var tabPanel = parent.Ext.getCmp(elements[0].id);
	parent.Ext.net.DirectMethods.OpenTab(tabPanel.id, url, tabPanel.items.length);
}